<template>
 <div>
    <home-page></home-page>  
   <swiper-home :swiperhomey="swiperhome"></swiper-home>  
   <home-icon :List="iconList"></home-icon>
    <recommend :recommlist="recommendlist"> </recommend>
   <weekend-home :weekendList="weekendList"></weekend-home>
 </div>
</template>
<script>
import SwiperHome from './components/swiper'
import HomePage from './components/header'
import HomeIcon from './components/icon'
import Recommend from './components/recommend'
import WeekendHome from './components/weekend'
import axios from 'axios'
import Axios from 'axios';
import { mapState } from 'vuex'
export default {
    name: 'Home',
   data () {
     return {

     }
   },
    components: {
      HomePage, 
      //    
      SwiperHome,
      HomeIcon,
      Recommend,
      WeekendHome
   },
   data () {
     return {
        lastCity:"",
        swiperhome:[],
        recommendlist:[],
        iconList:[],
        weekendList:[]
     }
   },
   methods:{
     getHomeInfo(){
       axios.get("/api/index.json?city="+this.city).then(this.getHomeInfoSucc)  
     },
     getHomeInfoSucc(response){
      let res = response.data
      if(res.ret&&res.data){
         
          this.swiperhome = res.data.swiperList
          this.iconList = res.data.iconList
          this.recommendlist = res.data.recommendList
          this.weekendList = res.data.weekendList
          
      }
     }
},
computed : {
  ...mapState(['city'])
},
   mounted () {
     //临时缓存变量this.lastCity
     this.lastCity = this.city
     this.getHomeInfo()
   },
   // 
  //  页面从新显示的时候
   activated () {
     console.log(this.lastCity)
      if(this.lastCity!==this.city){
          console.log(this.lastCity ,this.city)
        this.lastCity = this.city
        this.getHomeInfo()
      }
    },
  
}
</script>

<style>

</style>
